package com.zyl.blog.rbac.web.controller;

import com.zyl.blog.common.config.anno.SysLog;
import com.zyl.blog.common.domain.rbac.vo.user.UserInfoVO;
import com.zyl.blog.common.enums.BusinessType;
import com.zyl.blog.common.enums.OperationType;
import com.zyl.blog.common.response.Result;
import com.zyl.blog.rbac.service.rbac.UserService;
import io.swagger.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @version v1.0
 * @ProjectName: Personal_Blog_Server
 * @Package: com.zyl.blog.rbac.web.controller
 * @ClassName: UserController
 * @Description:
 * @Author FinalFantasy
 * @Date 2025/9/5-10:40
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/user/")
public class UserController {

    private final UserService userService;

    /**
     * 用户信息业务
     *
     * @param userId 用户ID
     * @return {@link Result }<{@link ? }>
     */
    @Operation(summary = "加密获取用户信息")
    @SysLog(
            value = "用户信息业务（加密）",
            recordResult = true,
            businessType = BusinessType.USER,
            operationType = OperationType.QUERY
    )
    @GetMapping("info")
    public Result<?> getUserInfo(
            @RequestParam("userId") Long userId
    ) {
        return Result.ok(userService.getUserInfo(userId));
    }

    /**
     * 用户信息业务
     *
     * @param userId 用户ID
     * @return {@link Result }<{@link ? }>
     */
    @Operation(summary = "非加密获取用户信息")
    @SysLog(
            value = "用户信息业务（非加密）",
            recordResult = true,
            businessType = BusinessType.USER,
            operationType = OperationType.QUERY
    )
    @GetMapping("info/all")
    public Result<UserInfoVO> getUserInfoAll(
            @RequestParam("userId") Long userId
    ) {
        return Result.ok(userService.getUserInfoAll(userId));
    }

    /**
     * 退出登录业务
     *
     * @return {@link Result }<{@link ? }>
     */
    @Operation(summary = "退出登录")
    @SysLog(
            value = "退出登录",
            recordResult = true,
            businessType = BusinessType.AUTH,
            operationType = OperationType.LOGOUT
    )
    @PostMapping("logout")
    public Result<?> logout() {
        return Result.ok(userService.logout());
    }

    /**
     * 强制退出登录业务
     *
     * @return {@link Result }<{@link ? }>
     */
    @Operation(summary = "强制退出登录")
    @SysLog(
            value = "强制退出登录",
            recordResult = true,
            businessType = BusinessType.AUTH,
            operationType = OperationType.LOGOUT
    )
    @PostMapping("logout/force")
    public Result<?> forceLogout() {
        return Result.ok(userService.forceLogoutAll());
    }
}
